View Javadoc

1   /*******************************************************************************
2    * Copyright 2013 Ericsson Nikola Tesla d.d.
3    *
4    * See the NOTICE file distributed with this work for additional 
5    * information regarding copyright ownership
6    * 
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   ******************************************************************************/
19  
20  package org.universAAL.samples.sensor.simulator;
21  
22  import java.awt.EventQueue;
23  
24  import org.osgi.framework.BundleActivator;
25  import org.osgi.framework.BundleContext;
26  import org.universAAL.middleware.container.ModuleContext;
27  import org.universAAL.middleware.container.osgi.uAALBundleContainer;
28  import org.universAAL.middleware.container.utils.LogUtils;
29  
30  /**
31   * @author eandgrg
32   * 
33   */
34  public class Activator implements BundleActivator {
35      /**
36       * {@link ModuleContext}
37       */
38      private static ModuleContext mcontext;
39      LocationContextPublisher lp = null;
40      SensorSimulatorGUI frame = null;
41  
42      /*
43       * (non-Javadoc)
44       * 
45       * @see
46       * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
47       * )
48       */
49      public void start(BundleContext bcontext) throws Exception {
50  
51  	Activator.mcontext = uAALBundleContainer.THE_CONTAINER
52  		.registerModule(new Object[] { bcontext });
53  
54  	EventQueue.invokeLater(new Runnable() {
55  	    public void run() {
56  		try {
57  		    LocationContextPublisher lp = new LocationContextPublisher(
58  			    mcontext);
59  
60  		    LampStatePublisher lampStatePublisher = new LampStatePublisher(
61  			    mcontext);
62  		    RoomTemperaturePublisher roomTemperaturePublisher = new RoomTemperaturePublisher(
63  			    mcontext);
64  
65  		    RoomHumidityPublisher roomHumidityPublisher = new RoomHumidityPublisher(
66  			    mcontext);
67  
68  		    SensorSimulatorGUI frame = new SensorSimulatorGUI(lp,
69  			    lampStatePublisher, roomTemperaturePublisher,
70  			    roomHumidityPublisher);
71  		    frame.setVisible(true);
72  		} catch (Exception e) {
73  		    e.printStackTrace();
74  		}
75  	    }
76  	});
77  
78  	LogUtils
79  		.logInfo(
80  			mcontext,
81  			this.getClass(),
82  			"start",
83  			new Object[] { "smp.sensor.simulator.gui bundle has started." },
84  			null);
85      }
86  
87      /*
88       * (non-Javadoc)
89       * 
90       * @see
91       * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
92       */
93      public void stop(BundleContext context) throws Exception {
94  	LogUtils
95  		.logInfo(
96  			mcontext,
97  			this.getClass(),
98  			"stop",
99  			new Object[] { "smp.sensor.simulator.gui bundle has stopped." },
100 			null);
101 	mcontext = null;
102 	lp = null;
103 	frame = null;
104 
105     }
106 
107 }